<?php
class ome_finder_return_product{
    var $detail_basic = "售后服务详情";
    
    function detail_basic($return_id){
        $render = app::get('ome')->render();
        $oProduct = &app::get('ome')->model('return_product');
        $oProduct_items = &app::get('ome')->model('return_product_items');
        $oReturn_item = &app::get('ome')->model('return_process_items');
        $oOrder = &app::get('ome')->model('orders');

           if ($_POST['delivery_id']){
            foreach($_POST['item_id'] as $key => $val){
                $item = array();
                $item['item_id'] = $val;
                $branch_id = $_POST['branch_id'.$val];
                $item['branch_id'] = $branch_id;
                $oProduct_items->save($item);
           }
           $return_product['return_id'] = $return_id;
           $return_product['delivery_id'] = $_POST['delivery_id'];
           $oProduct->save($return_product);
        }
        
        $product_detail = $oProduct->product_detail($return_id);
        
        $order_id = $product_detail['order_id'];
        if (!$product_detail['delivery_id']){
            $product_items = array();
            if ($product_detail['items'])
               foreach($product_detail['items'] as $k=>$v){
                $refund = $oReturn_item->Get_refund_count($order_id,$v['bn']);
                $v['effective']=$refund;
                $v['branch']=$oReturn_item->getBranchCodeByBnAndOd($v['bn'],$order_id);
                $product_items[] = $v;
            }
            //获取仓库模式
            $branch_mode = &app::get('ome')->getConf('ome.branch.mode');
            $render->pagedata['branch_mode'] = $branch_mode;
            $product_detail['items'] = $product_items;
        }
        
        //增加售后服务详情显示前的扩展
        foreach(kernel::servicelist('ome.aftersale') as $o){
            if(method_exists($o,'pre_detail_display')){
                $o->pre_detail_display($product_detail);
            }
        }
        if (!is_numeric($product_detail['attachment'])){
            $render->pagedata['attachment_type'] = 'remote';
        }
        $render->pagedata['product'] = $product_detail;
        $render->pagedata['order'] = $oOrder->dump($product_detail['order_id']);
        return $render->fetch('admin/return_product/detail.html');
    }

}
?>